From 78c8d4efa9481073b6f24af836a2cc050ca36ba8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:09:46 +0000 Subject: [PATCH 001/126] Auto-generated commit c3bc3dc2511b24173309a12b6402185f4be4daa4 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 252 +++++ index.d.ts | 57 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 49 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3562 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..5613a07 --- /dev/null +++ b/README.md @@ -0,0 +1,252 @@ + + +# prepend + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Add elements from one collection to the beginning of another collection. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@esm/index.mjs'; +``` + +#### prepend( collection1, collection2 ) + +Adds elements from one `collection` to the beginning of another `collection`. A `collection` may be either an [`Array`][mdn-array], [`Typed Array`][mdn-typed-array], or an array-like [`Object`][mdn-object] (i.e., an [`Object`][mdn-object] having a valid writable `length` property). + +```javascript +var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + +var out = prepend( arr, [ 6.0, 7.0 ] ); +// returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] + +var bool = ( out === arr ); +// returns true +``` + +Note that the function returns the extended collection. For [typed arrays][mdn-typed-array], the returned value is a new [typed array][mdn-typed-array] view whose underlying [`ArrayBuffer`][mdn-arraybuffer] may **not** equal the underlying [`ArrayBuffer`][mdn-arraybuffer] for the input `collection`. + +```javascript +import ArrayBuffer from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs'; +import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; + +var buf = new ArrayBuffer( 3*8 ); // 8 bytes per double + +var arr = new Float64Array( buf, 8, 2 ); +arr[ 0 ] = 1.0; +arr[ 1 ] = 2.0; + +var out = prepend( arr, [ 3.0 ] ); +// returns [ 3.0, 1.0, 2.0 ] + +var bool = ( out === arr ); +// returns false + +bool = ( out.buffer === arr.buffer ); +// returns true + +out = prepend( out, [ 4.0 ] ); +// returns [ 4.0, 3.0, 1.0, 2.0 ] + +bool = ( out.buffer === arr.buffer ); +// returns false +``` + +
+ + + + + +
+ +## Notes + +- The function adds elements to a [typed array][mdn-typed-array] by setting values in the underlying [`ArrayBuffer`][mdn-arraybuffer]. If an [`ArrayBuffer`][mdn-arraybuffer] does not have enough bytes in which to store all elements, the function allocates a new [`ArrayBuffer`][mdn-arraybuffer] capable of holding `2^n` elements, where `n` is the next power of `2`. This procedure is similar to how environments internally handle dynamic memory allocation for [`Arrays`][mdn-array]. +- Beware when providing [typed arrays][mdn-typed-array] which are views pointing to a shared (or pooled) [`ArrayBuffer`][mdn-arraybuffer]. Because the function sets [`ArrayBuffer`][mdn-arraybuffer] bytes outside of a provided [view][mdn-typed-array], the function may overwrite bytes belonging to one or more external views. This could be a potential **security vulnerability**. Prefer providing [typed arrays][mdn-typed-array] which have an exclusive [`ArrayBuffer`][mdn-arraybuffer]; otherwise, be sure to plan for and guard against mutated state. + +
+ + + + + +
+ +## 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..a1c799b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { Collection } from '@stdlib/types/object'; + +/** +* Adds elements from one collection to the beginning of another collection. +* +* ## Notes +* +* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. +* - For purposes of generality, always treat the output collection as distinct from the input collection. +* +* @param collection1 - collection +* @param collection2 - collection containing elements to add +* @returns updated collection +* +* @example +* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* arr = prepend( arr, [ 6.0, 7.0 ] ); +* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float64Array = require( `@stdlib/array/float64` ); +* +* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* arr = prepend( arr, [ 6.0, 7.0 ] ); +* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length + + +// EXPORTS // + +export = prepend; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7135f59 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";var a=i,l=o;var m=e,d=t,f=r,h=n,u=s,j=function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e},c=function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s=0)return c(e,t);throw new TypeError(u("invalid argument. First argument must be either an Array, Typed Array, or an array-like object. Value: `%s`.",e))};export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3e00f79 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/prepend_object.js","../lib/prepend_typed_array.js","../lib/prepend.js","../lib/prepend_array.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// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an Array, Typed Array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar prepend = require( './prepend.js' );\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n"],"names":["ArrayBuffer","require$$0","ceil2","require$$1","isArray","isCollection","isTypedArrayLike","require$$2","isInteger","require$$3","format","require$$4","prependArray","arr","items","i","length","unshift","prependObject","obj","len","n","prependTypedArray","nbytes","ibytes","offset","buf","v","BYTES_PER_ELEMENT","byteOffset","byteLength","constructor","buffer","lib","collection1","collection2","TypeError"],"mappings":";;0lBA+DA,ICzCIA,EAAcC,EACdC,EAAQC,EAkEZ,ICnEIC,EAAUH,EACVI,EAAeF,EACfG,EAAmBC,EACnBC,EAAYC,EACZC,EAASC,EACTC,ECSJ,SAAkBC,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,GDbJK,EFYJ,SAAkBC,EAAKL,GACtB,IAAIM,EACAC,EACAN,EAMJ,IAJAK,EAAMD,EAAIH,OACVK,EAAIP,EAAME,OAGJD,EAAIK,EAAI,EAAGL,GAAK,EAAGA,IACxBI,EAAKJ,EAAEM,GAAMF,EAAKJ,GAGnB,IAAMA,EAAI,EAAGA,EAAIM,EAAGN,IACnBI,EAAKJ,GAAMD,EAAOC,GAGnB,OADAI,EAAIH,OAASI,EAAMC,EACZF,GE5BJG,EDqBJ,SAAkBT,EAAKC,GACtB,IAAIS,EACAC,EACAC,EAEAL,EACAM,EACAL,EACAM,EACAZ,EAQJ,GANAK,EAAMP,EAAIG,OAGVQ,GAFAH,EAAIP,EAAME,QAEGH,EAAIe,mBACjBH,EAASZ,EAAIgB,YAECL,EAMb,IALAD,EAASH,EAAMP,EAAIe,kBAGnBH,GADAC,EAAM,IAAI1B,EAAaE,EADfqB,EAASC,EAASC,EACU,KACvBK,WAAaP,EAASC,EACnCG,EAAI,IAAId,EAAIkB,YAAaL,EAAKD,EAAQL,EAAIC,GACpCN,EAAI,EAAGA,EAAIK,EAAKL,IACrBY,EAAGZ,EAAEM,GAAMR,EAAKE,QAGjBU,GAAUD,EACVG,EAAI,IAAId,EAAIkB,YAAalB,EAAImB,OAAQP,EAAQL,EAAIC,GAElD,IAAMN,EAAI,EAAGA,EAAIM,EAAGN,IACnBY,EAAGZ,GAAMD,EAAOC,GAEjB,OAAOY,GCER,IErCAM,EFUA,SAAkBC,EAAaC,GAC9B,IAAM9B,EAAc8B,GACnB,MAAM,IAAIC,UAAW1B,EAAQ,+EAAgFyB,IAE9G,GAAK/B,EAAS8B,GACb,OAAOtB,EAAcsB,EAAaC,GAGnC,GAAK7B,EAAkB4B,GACtB,OAAOZ,EAAmBY,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYlB,QACnBR,EAAW0B,EAAYlB,SACvBkB,EAAYlB,QAAU,EAEtB,OAAOE,EAAegB,EAAaC,GAEpC,MAAM,IAAIC,UAAW1B,EAAQ,+GAAgHwB"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e169d6d --- /dev/null +++ b/package.json @@ -0,0 +1,49 @@ +{ + "name": "@stdlib/utils-prepend", + "version": "0.0.0", + "description": "Add elements from one collection to the beginning of another collection.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/utils-prepend.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "unshift", + "prepend", + "append", + "extend", + "lengthen", + "array", + "typed array", + "typed-array", + "float64array", + "float32array", + "int32array", + "uint32array", + "int16array", + "uint16array", + "int8array", + "uint8array", + "uint8clampedarray", + "array-like", + "object", + "obj" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69d5b2d --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 74cc6e9ce72f67d21c2fd2e2cd462f179303e89c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 01:02:53 +0000 Subject: [PATCH 002/126] Transform error messages --- lib/prepend.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prepend.js b/lib/prepend.js index 1d8faba..b5066e2 100644 --- a/lib/prepend.js +++ b/lib/prepend.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 1bdf1158c54d8bc4da38a15dbe8570ac8d602d52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 12:44:26 +0000 Subject: [PATCH 003/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7135f59..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";var a=i,l=o;var m=e,d=t,f=r,h=n,u=s,j=function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e},c=function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s=0)return c(e,t);throw new TypeError(u("invalid argument. First argument must be either an Array, Typed Array, or an array-like object. Value: `%s`.",e))};export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3e00f79..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/prepend_object.js","../lib/prepend_typed_array.js","../lib/prepend.js","../lib/prepend_array.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// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an Array, Typed Array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar prepend = require( './prepend.js' );\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n"],"names":["ArrayBuffer","require$$0","ceil2","require$$1","isArray","isCollection","isTypedArrayLike","require$$2","isInteger","require$$3","format","require$$4","prependArray","arr","items","i","length","unshift","prependObject","obj","len","n","prependTypedArray","nbytes","ibytes","offset","buf","v","BYTES_PER_ELEMENT","byteOffset","byteLength","constructor","buffer","lib","collection1","collection2","TypeError"],"mappings":";;0lBA+DA,ICzCIA,EAAcC,EACdC,EAAQC,EAkEZ,ICnEIC,EAAUH,EACVI,EAAeF,EACfG,EAAmBC,EACnBC,EAAYC,EACZC,EAASC,EACTC,ECSJ,SAAkBC,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,GDbJK,EFYJ,SAAkBC,EAAKL,GACtB,IAAIM,EACAC,EACAN,EAMJ,IAJAK,EAAMD,EAAIH,OACVK,EAAIP,EAAME,OAGJD,EAAIK,EAAI,EAAGL,GAAK,EAAGA,IACxBI,EAAKJ,EAAEM,GAAMF,EAAKJ,GAGnB,IAAMA,EAAI,EAAGA,EAAIM,EAAGN,IACnBI,EAAKJ,GAAMD,EAAOC,GAGnB,OADAI,EAAIH,OAASI,EAAMC,EACZF,GE5BJG,EDqBJ,SAAkBT,EAAKC,GACtB,IAAIS,EACAC,EACAC,EAEAL,EACAM,EACAL,EACAM,EACAZ,EAQJ,GANAK,EAAMP,EAAIG,OAGVQ,GAFAH,EAAIP,EAAME,QAEGH,EAAIe,mBACjBH,EAASZ,EAAIgB,YAECL,EAMb,IALAD,EAASH,EAAMP,EAAIe,kBAGnBH,GADAC,EAAM,IAAI1B,EAAaE,EADfqB,EAASC,EAASC,EACU,KACvBK,WAAaP,EAASC,EACnCG,EAAI,IAAId,EAAIkB,YAAaL,EAAKD,EAAQL,EAAIC,GACpCN,EAAI,EAAGA,EAAIK,EAAKL,IACrBY,EAAGZ,EAAEM,GAAMR,EAAKE,QAGjBU,GAAUD,EACVG,EAAI,IAAId,EAAIkB,YAAalB,EAAImB,OAAQP,EAAQL,EAAIC,GAElD,IAAMN,EAAI,EAAGA,EAAIM,EAAGN,IACnBY,EAAGZ,GAAMD,EAAOC,GAEjB,OAAOY,GCER,IErCAM,EFUA,SAAkBC,EAAaC,GAC9B,IAAM9B,EAAc8B,GACnB,MAAM,IAAIC,UAAW1B,EAAQ,+EAAgFyB,IAE9G,GAAK/B,EAAS8B,GACb,OAAOtB,EAAcsB,EAAaC,GAGnC,GAAK7B,EAAkB4B,GACtB,OAAOZ,EAAmBY,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYlB,QACnBR,EAAW0B,EAAYlB,SACvBkB,EAAYlB,QAAU,EAEtB,OAAOE,EAAegB,EAAaC,GAEpC,MAAM,IAAIC,UAAW1B,EAAQ,+GAAgHwB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69d5b2d..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4a47fbc467207024b391ddba75b8651084fba93c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 12:45:04 +0000 Subject: [PATCH 004/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/prepend.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 43 files changed, 2715 insertions(+), 4380 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/prepend.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 932e8ce..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:37:24.644Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a1c165d --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index df3ff6e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var prepend = require( './prepend.js' ); - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend.js b/lib/prepend.js deleted file mode 100644 index b5066e2..0000000 --- a/lib/prepend.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7e389cb --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 5d1ee40617f3f2a04deae6e699b639f75c9228eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:14:08 +0000 Subject: [PATCH 005/126] Transform error messages --- lib/prepend.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prepend.js b/lib/prepend.js index 1d8faba..b5066e2 100644 --- a/lib/prepend.js +++ b/lib/prepend.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 2b832ed3e9f498e42037b3082a62f3820d1b9305 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 05:58:43 +0000 Subject: [PATCH 006/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a1c165d..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7e389cb..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ef337005eb24defa0b2f3db9de4b100340283bbb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 05:59:26 +0000 Subject: [PATCH 007/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/prepend.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 43 files changed, 2715 insertions(+), 4380 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/prepend.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 ffd5a31..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:31:46.895Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a1c165d --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index df3ff6e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var prepend = require( './prepend.js' ); - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend.js b/lib/prepend.js deleted file mode 100644 index b5066e2..0000000 --- a/lib/prepend.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c4e4df1 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 264daae31fb420679308d5754a4783d9f50eadde Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 12:46:32 +0000 Subject: [PATCH 008/126] Transform error messages --- lib/prepend.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prepend.js b/lib/prepend.js index 1d8faba..b5066e2 100644 --- a/lib/prepend.js +++ b/lib/prepend.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 11534b1d3f96fecec77e96b4aacaed978dfad2e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:10:28 +0000 Subject: [PATCH 009/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a1c165d..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c4e4df1..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a9ebe80d9e6795cdcd58c50334ed6936aa1dbc5d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:11:18 +0000 Subject: [PATCH 010/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/prepend.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 42 files changed, 2715 insertions(+), 4345 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/prepend.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a1c165d --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index df3ff6e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var prepend = require( './prepend.js' ); - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend.js b/lib/prepend.js deleted file mode 100644 index b5066e2..0000000 --- a/lib/prepend.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f675010 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 18cbeb46ff05219611fba5df579f02f0fe138a8b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:52:26 +0000 Subject: [PATCH 011/126] Transform error messages --- lib/prepend.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prepend.js b/lib/prepend.js index 1d8faba..b5066e2 100644 --- a/lib/prepend.js +++ b/lib/prepend.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From a92cb141aca6c4c34f03161637dce7b55c79221a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:53:05 +0000 Subject: [PATCH 012/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a1c165d..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f675010..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1a36ed1d7e252e34e046b6edca2b34bdb3bd50b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:53:49 +0000 Subject: [PATCH 013/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/prepend.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 43 files changed, 2715 insertions(+), 4419 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/prepend.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 08719a2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:34:25.647Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index df3ff6e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var prepend = require( './prepend.js' ); - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend.js b/lib/prepend.js deleted file mode 100644 index b5066e2..0000000 --- a/lib/prepend.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..07849d1 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 3dd7b9f97e13587cec7cccd9d28c44009ac2d810 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:43:35 +0000 Subject: [PATCH 014/126] Transform error messages --- lib/prepend.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prepend.js b/lib/prepend.js index 1d8faba..b5066e2 100644 --- a/lib/prepend.js +++ b/lib/prepend.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 1ee5bed1a2cc298ea09012d5db85e2b9627938f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:04:41 +0000 Subject: [PATCH 015/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 07849d1..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 85ee4fd23c756111ac1557c94027b152e872b46b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:05:23 +0000 Subject: [PATCH 016/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/prepend.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 43 files changed, 2715 insertions(+), 4435 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/prepend.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 0c0b258..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:33:37.928Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index df3ff6e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var prepend = require( './prepend.js' ); - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend.js b/lib/prepend.js deleted file mode 100644 index b5066e2..0000000 --- a/lib/prepend.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..79be682 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 77259d47311f6ad501891c6733797186c8007e86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:11:21 +0000 Subject: [PATCH 017/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From f47fb5e1d1666e623c381c526b7c1dc405006e76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:02:38 +0000 Subject: [PATCH 018/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 79be682..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7908dbaa9391379d7be046099f700bee486853f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:03:23 +0000 Subject: [PATCH 019/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 -- benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 357 --- 43 files changed, 2715 insertions(+), 4435 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 601304a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:00:38.641Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1dd7db9 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 01342b75021e1f8489f7f1be6e400c9e231f74d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:56:44 +0000 Subject: [PATCH 020/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 0e1a4dcb34e610b3f10fdea451e2c71017e898a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:55:35 +0000 Subject: [PATCH 021/126] Remove files --- index.d.ts | 57 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2751 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,EDsBCK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,EFhBCQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,EHoBCC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1dd7db9..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b31a6a2213528a1fdca62665086266d1345255dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:56:23 +0000 Subject: [PATCH 022/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 4070 insertions(+), 4435 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 bbe4299..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:46:54.567Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9b30b76 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From b2167be4e7d3632e9d46e8d4967130064305c5af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:31:19 +0000 Subject: [PATCH 023/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index a5f298e..bf36b8b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From fcc9ab3128e521fe47a7ca90c2bb9e9ba3a65952 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:23:21 +0000 Subject: [PATCH 024/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4106 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9b30b76..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e769c7fc591f682b86ad18e96df5410fae8bcc64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:24:09 +0000 Subject: [PATCH 025/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 4070 insertions(+), 4456 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 b820b7e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:40:22.528Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index bf36b8b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..65d0005 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 9af244c37de6bfa48b84a51c880731d0294c7f63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:28:22 +0000 Subject: [PATCH 026/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 06eb7bd..9189597 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 21c9c67ed0f579c5d5267023c899d8e86fe592b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 12:20:49 +0000 Subject: [PATCH 027/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4106 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport ceil2 from '@stdlib/math-base-special-ceil2' ; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64' ;\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 65d0005..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 641b05be059408a8904391b20bcdfd5195052968 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 12:21:47 +0000 Subject: [PATCH 028/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 4070 insertions(+), 4461 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 fe9b06a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:29:34.306Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5c4e8b5 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 9189597..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..735fbcf --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From b94dd5d670a3cd95d11a265609437ab1d3927722 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:11:12 +0000 Subject: [PATCH 029/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 6d7533b..b8d657b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 38f9a4e1f5151f1d0a7bfeb866045f71bda3bd7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:01:26 +0000 Subject: [PATCH 030/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4106 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5c4e8b5..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 735fbcf..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f0870ebbe0a99b44bca9690cb155de0ac9d070cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:02:05 +0000 Subject: [PATCH 031/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 4070 insertions(+), 4472 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 f4f2dc7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:38:52.865Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b2aee62 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index b8d657b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..51fca4c --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 2ff09456034ac887676e54dd2aa5189e58177d1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:07:30 +0000 Subject: [PATCH 032/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 6d7533b..b8d657b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.x", "@stdlib/assert-is-typed-array-like": "^0.0.x", "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 6d7cbf8d6d8b36b80034036ce72a5c1b0b194a90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:42:46 +0000 Subject: [PATCH 033/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4106 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b2aee62..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;mmBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 51fca4c..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a7f87f1f747755ae523ff36ee72ec400e60233b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:43:23 +0000 Subject: [PATCH 034/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 6203 insertions(+), 4472 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 f7ac360..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:14:11.839Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index aea2172..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..747d731 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index b8d657b..00e2070 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/constants-int16-max": "^0.0.x", - "@stdlib/constants-int32-max": "^0.0.x", - "@stdlib/constants-int8-max": "^0.0.x", - "@stdlib/constants-uint16-max": "^0.0.x", - "@stdlib/constants-uint32-max": "^0.0.x", - "@stdlib/constants-uint8-max": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..37b67a9 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 596f805d3c5db733d9b60975d7ea4edf627af099 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 10:04:05 +0000 Subject: [PATCH 035/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 9cfd52b..ba234b8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.8", "@stdlib/assert-is-typed-array-like": "^0.0.8", "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From d044a5c9cef0742a2c8999d0cd35245607d75f13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 19:20:04 +0000 Subject: [PATCH 036/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 747d731..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 37b67a9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bd843e275292103eb175e4835bae66b64661efd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 19:20:57 +0000 Subject: [PATCH 037/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 6203 insertions(+), 4607 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 d22f723..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T06:26:25.124Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..747d731 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index ba234b8..8685083 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-int16-max": "^0.0.7", - "@stdlib/constants-int32-max": "^0.0.7", - "@stdlib/constants-int8-max": "^0.0.7", - "@stdlib/constants-uint16-max": "^0.0.7", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/constants-uint8-max": "^0.0.7", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e7e3caf --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From cf5cba17327df5e579459a4e400ee5a70ba2079c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 09:42:37 +0000 Subject: [PATCH 038/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 9cfd52b..ba234b8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.8", "@stdlib/assert-is-typed-array-like": "^0.0.8", "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From adf6aea5e18743a10c37ca2b105fc93126101d22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:05:38 +0000 Subject: [PATCH 039/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 747d731..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e7e3caf..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 489485e053ec942325db85d414461f6924a76ec7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:06:24 +0000 Subject: [PATCH 040/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 6203 insertions(+), 4613 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 ef5453e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T06:23:42.036Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 6f794b9..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 5a01fb3..a1c799b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..747d731 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index ba234b8..8685083 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-int16-max": "^0.0.7", - "@stdlib/constants-int32-max": "^0.0.7", - "@stdlib/constants-int8-max": "^0.0.7", - "@stdlib/constants-uint16-max": "^0.0.7", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/constants-uint8-max": "^0.0.7", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..189f964 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 116257ff59b7af794e226c34c3e5b2edb90e787e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jun 2023 03:24:22 +0000 Subject: [PATCH 041/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 9cfd52b..ba234b8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.8", "@stdlib/assert-is-typed-array-like": "^0.0.8", "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 09230f7d6abe7e920d96406342efb5d9ac9ac4a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jun 2023 03:24:53 +0000 Subject: [PATCH 042/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 a1c799b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 747d731..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 189f964..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f72e89323b45c2d13533f1db5834dd1a90926a40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Jun 2023 03:25:57 +0000 Subject: [PATCH 043/126] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 42 files changed, 6203 insertions(+), 4612 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 6b2569e..32e78ab 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..747d731 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index ba234b8..8685083 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-int16-max": "^0.0.7", - "@stdlib/constants-int32-max": "^0.0.7", - "@stdlib/constants-int8-max": "^0.0.7", - "@stdlib/constants-uint16-max": "^0.0.7", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/constants-uint8-max": "^0.0.7", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1de42e8 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 5e34365142a344a064d2473911a377ec9a69055e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 09:09:48 +0000 Subject: [PATCH 044/126] 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 1d8faba..b5066e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '0lF3A', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); diff --git a/package.json b/package.json index 9cfd52b..ba234b8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.8", "@stdlib/assert-is-typed-array-like": "^0.0.8", "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From ab3990ed1f94523568da3bbd65c81e949ca99d0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:22:42 +0000 Subject: [PATCH 045/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 32e78ab..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 747d731..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1de42e8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a32dbd0e0297c67876ff6638d9b96994c94632a1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:23:36 +0000 Subject: [PATCH 046/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 43 files changed, 6203 insertions(+), 4613 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 a8dd528..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T06:15:03.871Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 6b2569e..32e78ab 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/object'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..747d731 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5066e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '0lF3A', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index ba234b8..8685083 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-int16-max": "^0.0.7", - "@stdlib/constants-int32-max": "^0.0.7", - "@stdlib/constants-int8-max": "^0.0.7", - "@stdlib/constants-uint16-max": "^0.0.7", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/constants-uint8-max": "^0.0.7", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..942f60e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 53ac4599cb873e21499af3aab22fbf1140155b73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 18 Aug 2023 09:08:22 +0000 Subject: [PATCH 047/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..8f1d297 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi,Og', collection1 ) ); } diff --git a/package.json b/package.json index 9cfd52b..ba234b8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.0.8", "@stdlib/assert-is-typed-array-like": "^0.0.8", "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From a2171f316d36dc7f7b3ce5a06181f09ca4f7c013 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 18 Aug 2023 09:09:22 +0000 Subject: [PATCH 048/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 32e78ab..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/object'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 747d731..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,m){if(!e(m))throw new TypeError(n("0lF3A",m));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,m);if(r(l))return function(t,e){var r,s,n,l,m,d,f,a;if(l=t.length,s=(d=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '0lF3A', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 942f60e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b06985f454ff83d970d9af5f81c25144b0964c63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 18 Aug 2023 09:10:06 +0000 Subject: [PATCH 049/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 45 files changed, 6203 insertions(+), 4618 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -179,7 +172,7 @@ console.log( 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]. @@ -249,9 +242,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..aaa002f --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index ba234b8..8685083 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/constants-int16-max": "^0.0.7", - "@stdlib/constants-int32-max": "^0.0.7", - "@stdlib/constants-int8-max": "^0.0.7", - "@stdlib/constants-uint16-max": "^0.0.7", - "@stdlib/constants-uint32-max": "^0.0.7", - "@stdlib/constants-uint8-max": "^0.0.7", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..87adb58 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 8971f052aabc25697de1343daf3adc1403328893 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 06:06:07 +0000 Subject: [PATCH 050/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..8f1d297 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi,Og', collection1 ) ); } diff --git a/package.json b/package.json index b8485b1..21b1eea 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 12f9b853efe976ecebed717eebfa3d576b80aea4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 08:12:41 +0000 Subject: [PATCH 051/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index aaa002f..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;0mBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 87adb58..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 328509a76e2a06eca9b8698e900b5b5e0de3d290 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 08:13:24 +0000 Subject: [PATCH 052/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 357 -- 46 files changed, 6203 insertions(+), 4653 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 9c82fad..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f989074..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8b2f334 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;6oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 21b1eea..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-int16-max": "^0.1.0", - "@stdlib/constants-int32-max": "^0.1.0", - "@stdlib/constants-int8-max": "^0.1.0", - "@stdlib/constants-uint16-max": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.0", - "@stdlib/constants-uint8-max": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b80836a --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From be9d070fc3a0309180e24328bfa945b4326a6cce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 09:14:10 +0000 Subject: [PATCH 053/126] 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 8ed6f71..7a5afcb 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@esm/index.mjs'; +import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@v0.1.0-esm/index.mjs'; ``` #### prepend( collection1, collection2 ) @@ -129,7 +129,7 @@ bool = ( out.buffer === arr.buffer ); - - - - From f8ec2fc4aaaf0019f9a70c79954a68bca8816981 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 21:53:56 +0000 Subject: [PATCH 057/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 357 -- test/test.js | 357 -- 48 files changed, 6203 insertions(+), 5069 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 fc1a44d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T04:15:57.081Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d907bd9..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..99d88a7 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 21b1eea..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-int16-max": "^0.1.0", - "@stdlib/constants-int32-max": "^0.1.0", - "@stdlib/constants-int8-max": "^0.1.0", - "@stdlib/constants-uint16-max": "^0.1.0", - "@stdlib/constants-uint32-max": "^0.1.0", - "@stdlib/constants-uint8-max": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8d03052 --- /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 738adef..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From cdf1ab2b36f01389ea8e8a13657304805ff7d212 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 17:28:50 +0000 Subject: [PATCH 058/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..8f1d297 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi,Og', collection1 ) ); } diff --git a/package.json b/package.json index 4643982..67571e3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From e93a717c6f57b1fa65b412d7100fc0af926e284f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:02:52 +0000 Subject: [PATCH 059/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 99d88a7..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8d03052..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 511ef0ab1b40c3ac8feeee2f12f3dc45174181c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:03:53 +0000 Subject: [PATCH 060/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 357 -- test/test.js | 357 -- 47 files changed, 6203 insertions(+), 5068 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d907bd9..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..756c9ed --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 67571e3..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-int16-max": "^0.1.1", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.1.1", - "@stdlib/constants-uint16-max": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5ce47f3 --- /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 738adef..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From b7d7c0b1c62e616387e262234f4ced17309237f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 14:58:32 +0000 Subject: [PATCH 061/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..8f1d297 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi,Og', collection1 ) ); } diff --git a/package.json b/package.json index 4f02edb..65a4714 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d1391fb731b45e5599fb4dc395f29d1eb9068d06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:11:15 +0000 Subject: [PATCH 062/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 756c9ed..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ce47f3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From aae83dd34263e164dd4b290b24d37132dbfb1244 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:12:08 +0000 Subject: [PATCH 063/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 6203 insertions(+), 4753 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 8c970ac..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T04:30:43.252Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d907bd9..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..756c9ed --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 65a4714..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/constants-int16-max": "^0.1.1", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.1.1", - "@stdlib/constants-uint16-max": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ca89ac7 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 6fce6e8e4d240e631ec0bd9eb231d0f9879b391a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 11:23:19 +0000 Subject: [PATCH 064/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..8f1d297 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi,Og', collection1 ) ); } diff --git a/package.json b/package.json index 3214e26..c8e1c5c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 73b0d6d44f3bc7e3c9835c829b674ddc03f23bce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:26:41 +0000 Subject: [PATCH 065/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 756c9ed..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ca89ac7..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 759597e135c0af750a641ec2d693bb56e5f53c40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:27:20 +0000 Subject: [PATCH 066/126] 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 | 43 +- benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 6203 insertions(+), 4748 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 0f06284..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T04:41:16.266Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 d907bd9..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 68bdf25..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index fa2f0fb..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b5bebd1..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index 4e2590b..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..756c9ed --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 8f1d297..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y,Ix', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi,Og', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index c8e1c5c..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/constants-int16-max": "^0.1.1", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.1.1", - "@stdlib/constants-uint16-max": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1cc41af --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From adc8bf611541aa330cd802dc69ec513d6740f2e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 06:42:04 +0000 Subject: [PATCH 067/126] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dee0e97..437f7d9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 5884bfe05c0baf300c0c3d3cfc09d553a5bdc556 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:29:44 +0000 Subject: [PATCH 068/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 756c9ed..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y,Ix",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y,Ix', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi,Og', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,IAE1C,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,WAAYJ,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1cc41af..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bcbd8abdae99c5223211beebb82c861d42e57360 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:29:58 +0000 Subject: [PATCH 069/126] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 6203 insertions(+), 4754 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 51ab81d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T04:06:51.381Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ebe6963..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -190,7 +183,7 @@ console.log( 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]. @@ -260,9 +253,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e1dbc51..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 14a51b8..6041ede 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f4629d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function a(a,l){if(!t(l))throw new TypeError(s("invalid argument. Second argument must be an array-like object. Value: `%s`.",l));if(e(a))return function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e}(a,l);if(r(a))return function(e,t){var r,n,s,a,l,m,d,f;if(a=e.length,n=(m=t.length)*e.BYTES_PER_ELEMENT,(s=e.byteOffset)=0)return function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;2oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,+EAAgFH,IAE9G,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 1d8faba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 437f7d9..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/constants-int16-max": "^0.1.1", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.1.1", - "@stdlib/constants-uint16-max": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..be06f5e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From e35dc157fd1ab0910314661bc823e741f50564da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 07:13:27 +0000 Subject: [PATCH 070/126] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dee0e97..437f7d9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.1.0", "@stdlib/assert-is-typed-array-like": "^0.1.0", "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From a9e20c49933ee360e6f47a1d6804984d5dc3612d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 12:47:21 +0000 Subject: [PATCH 071/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 6041ede..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( `@stdlib/array/float64` ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f4629d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function a(a,l){if(!t(l))throw new TypeError(s("invalid argument. Second argument must be an array-like object. Value: `%s`.",l));if(e(a))return function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e}(a,l);if(r(a))return function(e,t){var r,n,s,a,l,m,d,f;if(a=e.length,n=(m=t.length)*e.BYTES_PER_ELEMENT,(s=e.byteOffset)=0)return function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;2oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,+EAAgFH,IAE9G,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index be06f5e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e79482591ee0cb31b074395b9805c3496ab42435 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 12:47:49 +0000 Subject: [PATCH 072/126] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 6203 insertions(+), 4759 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 a563bce..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T04:55:23.091Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ebe6963..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f4629d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function a(a,l){if(!t(l))throw new TypeError(s("invalid argument. Second argument must be an array-like object. Value: `%s`.",l));if(e(a))return function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e}(a,l);if(r(a))return function(e,t){var r,n,s,a,l,m,d,f;if(a=e.length,n=(m=t.length)*e.BYTES_PER_ELEMENT,(s=e.byteOffset)=0)return function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;2oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,+EAAgFH,IAE9G,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 1d8faba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 437f7d9..239ec17 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/constants-int16-max": "^0.1.1", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.1.1", - "@stdlib/constants-uint16-max": "^0.1.1", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..38cafe6 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 5178544430fc25d752851f284963548f9dbf29d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 13:47:50 +0000 Subject: [PATCH 073/126] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 048a7f7..96d6f58 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.0", "@stdlib/assert-is-typed-array-like": "^0.2.0", "@stdlib/math-base-special-ceil2": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 4c1ac0c0868ac0002209dc2687e50be72899680b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 20:48:59 +0000 Subject: [PATCH 074/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6239 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f4629d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function a(a,l){if(!t(l))throw new TypeError(s("invalid argument. Second argument must be an array-like object. Value: `%s`.",l));if(e(a))return function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e}(a,l);if(r(a))return function(e,t){var r,n,s,a,l,m,d,f;if(a=e.length,n=(m=t.length)*e.BYTES_PER_ELEMENT,(s=e.byteOffset)=0)return function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;2oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,+EAAgFH,IAE9G,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 38cafe6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From aa8ddf05cb490503033a5300f122cce9fc9a9b12 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 20:49:20 +0000 Subject: [PATCH 075/126] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 6203 insertions(+), 4762 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 204e158..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dde5c30 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";function a(a,l){if(!t(l))throw new TypeError(s("invalid argument. Second argument must be an array-like object. Value: `%s`.",l));if(e(a))return function(e,t){var r;for(r=t.length-1;r>=0;r--)e.unshift(t[r]);return e}(a,l);if(r(a))return function(e,t){var r,n,s,a,l,m,d,f;if(a=e.length,n=(m=t.length)*e.BYTES_PER_ELEMENT,(s=e.byteOffset)=0)return function(e,t){var r,n,s;for(r=e.length,n=t.length,s=r-1;s>=0;s--)e[s+n]=e[s];for(s=0;s[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;2oBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,+EAAgFH,IAE9G,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,+GAAgHJ,GAC9I"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 1d8faba..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 96d6f58..cce3cfa 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-typed-array-like": "^0.2.0", - "@stdlib/math-base-special-ceil2": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/constants-int16-max": "^0.2.0", - "@stdlib/constants-int32-max": "^0.1.1", - "@stdlib/constants-int8-max": "^0.2.0", - "@stdlib/constants-uint16-max": "^0.2.0", - "@stdlib/constants-uint32-max": "^0.1.1", - "@stdlib/constants-uint8-max": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a6a128e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 8ba45b646c67662eb5673cdb306e61a4437bbb2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 22:06:45 +0000 Subject: [PATCH 076/126] 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 9cf5487..00ed388 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@esm/index.mjs'; +import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@v0.2.0-esm/index.mjs'; ``` #### prepend( collection1, collection2 ) @@ -129,7 +129,7 @@ bool = ( out.buffer === arr.buffer ); - - - - From 7565ea639de91c7d1c46f61544f1c9e03cba76ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 05:26:55 +0000 Subject: [PATCH 080/126] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 73 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 4868 insertions(+), 4756 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bb2246b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index fa60eb2..4a1c807 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Add elements from one collection to the beginning of another collection.", "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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/constants-int16-max": "^0.2.1", - "@stdlib/constants-int32-max": "^0.2.1", - "@stdlib/constants-int8-max": "^0.2.1", - "@stdlib/constants-uint16-max": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/constants-uint8-max": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..075c237 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From f1f8999959f53abdd9286ef55c5c11bfb1d66b1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 07:22:32 +0000 Subject: [PATCH 081/126] 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 c70dd31..65738b5 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@esm/index.mjs'; +import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@v0.2.1-esm/index.mjs'; ``` #### prepend( collection1, collection2 ) @@ -129,7 +129,7 @@ bool = ( out.buffer === arr.buffer ); - - - - From 6705d827bb53ccac5bce1d6079d305c2dda9eb5c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 11:53:34 +0000 Subject: [PATCH 085/126] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4759 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 b1382ba..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T04:43:15.162Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c457506 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 72816c4..4a1c807 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^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-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/constants-int16-max": "^0.2.1", - "@stdlib/constants-int32-max": "^0.2.1", - "@stdlib/constants-int8-max": "^0.2.1", - "@stdlib/constants-uint16-max": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/constants-uint8-max": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48589b8 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 824553a7c841eac9bf1b38bdd3bcaa35b61167fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 05:53:16 +0000 Subject: [PATCH 086/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index ba54978..72816c4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-typed-array-like": "^0.2.1", "@stdlib/math-base-special-ceil2": "^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 1dd45d5d3c1d83b5c015f52d229e413b9dc5dc1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:04:01 +0000 Subject: [PATCH 087/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c457506..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48589b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5dd70e7840d6eb1752cec90873da436cbfb7f2b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:04:13 +0000 Subject: [PATCH 088/126] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4762 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 7b07b54..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T03:59:30.482Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c457506 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 72816c4..4a1c807 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^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-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/constants-int16-max": "^0.2.1", - "@stdlib/constants-int32-max": "^0.2.1", - "@stdlib/constants-int8-max": "^0.2.1", - "@stdlib/constants-uint16-max": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/constants-uint8-max": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48589b8 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From b303a1ff62e3d5a45d087192ee82403f8798474c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 02:16:56 +0000 Subject: [PATCH 089/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index ba54978..72816c4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.1", "@stdlib/assert-is-typed-array-like": "^0.2.1", "@stdlib/math-base-special-ceil2": "^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 d6ce58dec96c9894fb1e2d65f8fda1f89d56a9fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:46:57 +0000 Subject: [PATCH 090/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c457506..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48589b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 62f5b8c251615e9f6c43617c7477c86575d633a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:47:10 +0000 Subject: [PATCH 091/126] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 4868 insertions(+), 4763 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c457506 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 72816c4..4a1c807 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^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-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/constants-int16-max": "^0.2.1", - "@stdlib/constants-int32-max": "^0.2.1", - "@stdlib/constants-int8-max": "^0.2.1", - "@stdlib/constants-uint16-max": "^0.2.1", - "@stdlib/constants-uint32-max": "^0.2.1", - "@stdlib/constants-uint8-max": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48589b8 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 6fab3bd6466a913bb1e82aa28cfc25c089ff6a0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:06:09 +0000 Subject: [PATCH 092/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2a1d691..51d552f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 4f09044c782553e18db3d52db92f419a2ec11338 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:07:43 +0000 Subject: [PATCH 093/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c457506..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48589b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 34b5d8b9bb694bdc137d7af5f2c95d34c3de0acf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:07:56 +0000 Subject: [PATCH 094/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 48 files changed, 4868 insertions(+), 4962 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3f37db9 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 51d552f..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..962feb7 --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 3c0e0082a68f959e79442c4b9580ff95fc451475 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:09:15 +0000 Subject: [PATCH 095/126] 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 d7f13d9..02d4bd1 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@esm/index.mjs'; +import prepend from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-prepend@v0.2.2-esm/index.mjs'; ``` #### prepend( collection1, collection2 ) @@ -129,7 +129,7 @@ bool = ( out.buffer === arr.buffer ); - - - - From 259911effef81e4678ba11f3d95f55000a95efcd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 11:20:10 +0000 Subject: [PATCH 099/126] 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 | 148 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4920 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 2347672..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T04:49:46.559Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 9670cba..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 287dabba9bbbe6a435cf64a009c59cc645fff376 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 21:54:21 +0000 Subject: [PATCH 100/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 820ace3..9670cba 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 fe5731735ed984133259029a09fe77ab67d08e4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:06:45 +0000 Subject: [PATCH 101/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3ae41e89c1bf7e2738034f5dca3d6fca5a6930f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:07:04 +0000 Subject: [PATCH 102/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4965 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 c5a4dc8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T20:16:25.997Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 9670cba..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 7ec4134195d33fd2efbd4fa841a26db8e03e2072 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 06:59:54 +0000 Subject: [PATCH 103/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index a42071f..0d30a26 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 99f5908067a7c53073a2ea6445b3fcc9154c7c5d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:13:43 +0000 Subject: [PATCH 104/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ad0f2e39db94fa3c638e1919e5cc7c62b4d1b661 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:14:08 +0000 Subject: [PATCH 105/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4965 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 8bbc3dd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T05:09:17.368Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 0d30a26..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From dc319db12575b93c538e7c017dbd9906541524a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 07:18:12 +0000 Subject: [PATCH 106/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index a42071f..0d30a26 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 0792822a6a6bcc5af68af8d5b77b2187fd9bc06e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 11:53:19 +0000 Subject: [PATCH 107/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df66b788b7337039d1ac076c40b82f48c1944c1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 11:53:43 +0000 Subject: [PATCH 108/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4965 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 1f52a39..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T05:21:06.111Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 0d30a26..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 627f83e45fe893e2d4173068234e791261479b69 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 07:10:33 +0000 Subject: [PATCH 109/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index a42071f..0d30a26 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 eea47b6e51dd0a01b20e7091f5424f27595594f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:06:04 +0000 Subject: [PATCH 110/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 61bd203e3641ff2957f4e95ff745658b7beb8223 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:06:17 +0000 Subject: [PATCH 111/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 49 files changed, 4868 insertions(+), 4965 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 fd076d0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T05:25:01.049Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index 0d30a26..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From e6d5fb6535dff205028f3c07b22a3cfeb071eec0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 07:25:42 +0000 Subject: [PATCH 112/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2af97a3..a8829c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 37d80916ce47c8358aefc2efc5a44ba40bed44d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:17:28 +0000 Subject: [PATCH 113/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0b5cc711d467b4725c6736f1c234a3f56a9e24ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:17:46 +0000 Subject: [PATCH 114/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 50 files changed, 4868 insertions(+), 5070 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 9bdcf68..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T05:32:56.910Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index a8829c7..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 6d2133519bbdbe879e81480737da0d222f9a34aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:06:44 +0000 Subject: [PATCH 115/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2af97a3..a8829c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 511e78c333c77b500bc69f2df7c090e10050f3cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:31:19 +0000 Subject: [PATCH 116/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cc70a97c8e96b23fa483b93f84e77d912e4be445 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:31:33 +0000 Subject: [PATCH 117/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 50 files changed, 4868 insertions(+), 5070 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 0779e8a..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 = 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 40c4a2c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-23T01:58:38.192Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9882704 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index a8829c7..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 8dfd3d028803147eb8d975903749ad7d360589cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Feb 2025 00:41:14 +0000 Subject: [PATCH 118/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2af97a3..a8829c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 2b4e7fd818354ae12000489d3f137becbc95dfc0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Feb 2025 00:52:01 +0000 Subject: [PATCH 119/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9882704..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c92828b5bef344cbc905ac815ae2bf7f50433548 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Feb 2025 00:52:20 +0000 Subject: [PATCH 120/126] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 50 files changed, 4868 insertions(+), 5069 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 5f26c5c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-10T00:38:02.625Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b0377e..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8efe6f4 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index a8829c7..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 67a20c77be9e4f24d6170c8f40e216e89ba91c9c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:35:38 +0000 Subject: [PATCH 121/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2af97a3..a8829c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 2ae6b3d2ad791935023a51bc7b587d5d966330b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:08:26 +0000 Subject: [PATCH 122/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8efe6f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8b41bd9f7d22bb9f52b89bb663c4f31049cf7977 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 02:08:44 +0000 Subject: [PATCH 123/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 50 files changed, 4868 insertions(+), 5073 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 32e8697..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:23:51.253Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8905fbb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8efe6f4 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index a8829c7..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -}); From 5e4430c335e8e79c0a678f58cfda1d01ec991409 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:16:53 +0000 Subject: [PATCH 124/126] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d8faba..b5ce493 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isArray = require( '@stdlib/assert-is-array' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var prependArray = require( './prepend_array.js' ); var prependObject = require( './prepend_object.js' ); var prependTypedArray = require( './prepend_typed_array.js' ); @@ -58,7 +58,7 @@ var prependTypedArray = require( './prepend_typed_array.js' ); */ function prepend( collection1, collection2 ) { if ( !isCollection( collection2 ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) ); + throw new TypeError( format( '1Wn2y', collection2 ) ); } if ( isArray( collection1 ) ) { return prependArray( collection1, collection2 ); @@ -77,7 +77,7 @@ function prepend( collection1, collection2 ) { ) { return prependObject( collection1, collection2 ); } - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) ); + throw new TypeError( format( '1WnAi', collection1 ) ); } diff --git a/package.json b/package.json index 2af97a3..a8829c7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-integer": "^0.2.2", "@stdlib/assert-is-typed-array-like": "^0.2.2", "@stdlib/math-base-special-ceil2": "^0.3.0", - "@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 0d3ec54d014ed1a78f51d5ff1c8573105c417f7e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:36:37 +0000 Subject: [PATCH 125/126] Remove files --- index.d.ts | 57 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4904 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 18fa31c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; - -/** -* Adds elements from one collection to the beginning of another collection. -* -* ## Notes -* -* - If the input collection is a typed array, the output value does not equal the input reference and the underlying `ArrayBuffer` may *not* be the same as the `ArrayBuffer` belonging to the input view. -* - For purposes of generality, always treat the output collection as distinct from the input collection. -* -* @param collection1 - collection -* @param collection2 - collection containing elements to add -* @returns updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function prepend( collection1: Collection, collection2: Collection ): Collection; - - -// EXPORTS // - -export = prepend; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8efe6f4..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e41ad6e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1389dec9616011aa7819414f033124cbfebd2bb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:36:54 +0000 Subject: [PATCH 126/126] 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 | 193 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 94 - benchmark/benchmark.object.js | 77 - benchmark/benchmark.preallocation.js | 138 - benchmark/benchmark.typed_array.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 51 - examples/index.js | 35 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 86 - lib/prepend_array.js | 48 - lib/prepend_object.js | 64 - lib/prepend_typed_array.js | 90 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 50 files changed, 4868 insertions(+), 5073 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 benchmark/benchmark.object.js delete mode 100644 benchmark/benchmark.preallocation.js delete mode 100644 benchmark/benchmark.typed_array.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 (95%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/prepend_array.js delete mode 100644 lib/prepend_object.js delete mode 100644 lib/prepend_typed_array.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 86ed915..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T01:07:46.612Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8905fbb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 b69a5af..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 be2bd7f..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: '10 22 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -192,7 +183,7 @@ console.log( 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]. @@ -265,9 +256,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append +[@stdlib/utils/append]: https://github.com/stdlib-js/utils-append/tree/esm -[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift +[@stdlib/utils/unshift]: https://github.com/stdlib-js/utils-unshift/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 73600b1..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in', function benchmark( b ) { - var arr; - var i; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.unshift( i, i+1, i+2 ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,apply', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.object.js b/benchmark/benchmark.object.js deleted file mode 100644 index 45c69fd..0000000 --- a/benchmark/benchmark.object.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::object', function benchmark( b ) { - var arr; - var i; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::built-in,object', function benchmark( b ) { - var unshift; - var arr; - var i; - - unshift = Array.prototype.unshift; - - arr = { - 'length': 0 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - unshift.apply( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.preallocation.js b/benchmark/benchmark.preallocation.js deleted file mode 100644 index b3d930d..0000000 --- a/benchmark/benchmark.preallocation.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array,preallocated', function benchmark( b ) { - var arr; - var buf; - var i; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, buf.byteLength, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,preallocated,no-wrapper', function benchmark( b ) { - var prepend; - var arr; - var buf; - var i; - - prepend = require( './../lib/prepend_typed_array.js' ); - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Here, we are only testing the operation of creating a new view each time a value must be added to a typed array: - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float64array,control,preallocated,constructor,value', function benchmark( b ) { - var offset; - var arr; - var buf; - var i; - var j; - var k; - - buf = new ArrayBuffer( b.iterations*8*3 ); // 8 bytes per double - arr = new Float64Array( buf, b.iterations*8*3, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - k = 3 * (i+1); - offset = arr.byteOffset - ( arr.BYTES_PER_ELEMENT*3 ); - arr = new Float64Array( arr.buffer, offset, k ); - for ( j = 0; j < 3; j++ ) { - arr[ j ] = i + j; - } - if ( arr.length !== k ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.typed_array.js b/benchmark/benchmark.typed_array.js deleted file mode 100644 index c0de4d0..0000000 --- a/benchmark/benchmark.typed_array.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 MAX_INT32 = require( '@stdlib/constants-int32-max' ); -var MAX_UINT32 = require( '@stdlib/constants-uint32-max' ); -var MAX_INT16 = require( '@stdlib/constants-int16-max' ); -var MAX_UINT16 = require( '@stdlib/constants-uint16-max' ); -var MAX_INT8 = require( '@stdlib/constants-int8-max' ); -var MAX_UINT8 = require( '@stdlib/constants-uint8-max' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var pkg = require( './../package.json' ).name; -var prepend = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::float64array', function benchmark( b ) { - var arr; - var i; - - arr = new Float64Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::float32array', function benchmark( b ) { - var arr; - var i; - - arr = new Float32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i, i+1, i+2 ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT32 + 1; - arr = new Int32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint32array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT32 + 1; - arr = new Uint32Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT16 + 1; - arr = new Int16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint16array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT16 + 1; - arr = new Uint16Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::int8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_INT8 + 1; - arr = new Int8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8array', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8Array(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::uint8clampedarray', function benchmark( b ) { - var arr; - var max; - var i; - - max = MAX_UINT8 + 1; - arr = new Uint8ClampedArray(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = prepend( arr, [ i%max, (i+1)%max, (i+2)%max ] ); - if ( arr.length !== 3*(i+1) ) { - b.fail( 'should have added an element' ); - } - } - b.toc(); - if ( arr.length !== b.iterations*3 ) { - b.fail( 'should have added elements' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7ab9b33..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend" -%% click B href "https://github.com/stdlib-js/utils-prepend/tree/main" -%% click C href "https://github.com/stdlib-js/utils-prepend/tree/production" -%% click D href "https://github.com/stdlib-js/utils-prepend/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-prepend/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-prepend/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/prepend -[production-url]: https://github.com/stdlib-js/utils-prepend/tree/production -[deno-url]: https://github.com/stdlib-js/utils-prepend/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-prepend/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-prepend/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-prepend/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-prepend/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-prepend/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 52155db..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import prepend from '../docs/types/index'; -export = prepend; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4bd891a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var v=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var h=v(function(C,g){ -function x(r,e){var n;for(n=e.length-1;n>=0;n--)r.unshift(e[n]);return r}g.exports=x -});var E=v(function(F,d){ -function A(r,e){var n,a,t;for(n=r.length,a=e.length,t=n-1;t>=0;t--)r[t+a]=r[t];for(t=0;t=0)return P(r,e);throw new TypeError(T('1WnAi',r))}w.exports=V -});var Y=m();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 d40da71..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/prepend_array.js", "../lib/prepend_object.js", "../lib/prepend_typed_array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar isInteger = require( '@stdlib/assert-is-integer' );\nvar format = require( '@stdlib/string-format' );\nvar prependArray = require( './prepend_array.js' );\nvar prependObject = require( './prepend_object.js' );\nvar prependTypedArray = require( './prepend_typed_array.js' );\n\n\n// MAIN //\n\n/**\n* Adds elements from one collection to the beginning of another collection.\n*\n* @param {Collection} collection1 - collection\n* @param {Collection} collection2 - collection containing elements to add\n* @throws {TypeError} first argument must be either an array, typed array, or an array-like object\n* @throws {TypeError} second argument must be an array-like object\n* @returns {Collection} updated collection\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or an array-like object. Value: `%s`.', collection1 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = prepend;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Add the elements of one collection to the beginning of another collection.\n*\n* @module @stdlib/utils-prepend\n*\n* @example\n* var prepend = require( '@stdlib/utils-prepend' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\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,cAoCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACJ,IAAMA,EAAID,EAAM,OAAO,EAAGC,GAAK,EAAGA,IACjCF,EAAI,QAASC,EAAOC,CAAE,CAAE,EAEzB,OAAOF,CACR,CAKAF,EAAO,QAAUC,IC/CjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAwCA,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EAMJ,IAJAF,EAAMF,EAAI,OACVG,EAAIF,EAAM,OAGJG,EAAIF,EAAI,EAAGE,GAAK,EAAGA,IACxBJ,EAAKI,EAAED,CAAE,EAAIH,EAAKI,CAAE,EAGrB,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAKI,CAAE,EAAIH,EAAOG,CAAE,EAErB,OAAAJ,EAAI,OAASE,EAAMC,EACZH,CACR,CAKAF,EAAO,QAAUC,IC/DjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,sBAAuB,EAC9CC,EAAQ,QAAS,iCAAkC,EA2BvD,SAASC,EAASC,EAAKC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GANAJ,EAAMN,EAAI,OACVQ,EAAIP,EAAM,OAEVE,EAASK,EAAIR,EAAI,kBACjBI,EAASJ,EAAI,WAERI,EAASD,EAMb,IALAD,EAASI,EAAMN,EAAI,kBACnBK,EAAQH,EAASC,EAASC,EAC1BG,EAAM,IAAIV,EAAaC,EAAOO,EAAM,CAAE,CAAE,EACxCD,EAASG,EAAI,WAAaL,EAASC,EACnCM,EAAI,IAAIT,EAAI,YAAaO,EAAKH,EAAQE,EAAIE,CAAE,EACtCE,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAGC,EAAEF,CAAE,EAAIR,EAAKU,CAAE,OAGnBN,GAAUD,EACVM,EAAI,IAAIT,EAAI,YAAaA,EAAI,OAAQI,EAAQE,EAAIE,CAAE,EAEpD,IAAME,EAAI,EAAGA,EAAIF,EAAGE,IACnBD,EAAGC,CAAE,EAAIT,EAAOS,CAAE,EAEnB,OAAOD,CACR,CAKAb,EAAO,QAAUG,ICzFjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,yBAA0B,EAC7CC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAY,QAAS,2BAA4B,EACjDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IACfC,EAAgB,IAChBC,EAAoB,IA6BxB,SAASC,EAASC,EAAaC,EAAc,CAC5C,GAAK,CAACT,EAAcS,CAAY,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+EAAgFM,CAAY,CAAE,EAE5H,GAAKV,EAASS,CAAY,EACzB,OAAOJ,EAAcI,EAAaC,CAAY,EAG/C,GAAKR,EAAkBO,CAAY,EAClC,OAAOF,EAAmBE,EAAaC,CAAY,EAGpD,GACCD,IAAgB,MAChB,OAAOA,GAAgB,UACvB,OAAOA,EAAY,QAAW,UAC9BN,EAAWM,EAAY,MAAO,GAC9BA,EAAY,QAAU,EAEtB,OAAOH,EAAeG,EAAaC,CAAY,EAEhD,MAAM,IAAI,UAAWN,EAAQ,+GAAgHK,CAAY,CAAE,CAC5J,CAKAV,EAAO,QAAUS,IC1CjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_prepend_array", "__commonJSMin", "exports", "module", "prepend", "arr", "items", "i", "require_prepend_object", "__commonJSMin", "exports", "module", "prepend", "obj", "items", "len", "n", "i", "require_prepend_typed_array", "__commonJSMin", "exports", "module", "ArrayBuffer", "ceil2", "prepend", "arr", "items", "nbytes", "ibytes", "offset", "total", "len", "buf", "n", "v", "i", "require_main", "__commonJSMin", "exports", "module", "isArray", "isCollection", "isTypedArrayLike", "isInteger", "format", "prependArray", "prependObject", "prependTypedArray", "prepend", "collection1", "collection2", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f308559..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( collection1, collection2 ) - Adds the elements of one collection to the beginning of another collection. - - If the input collection is a typed array, the output value does not equal - the input reference and the underlying `ArrayBuffer` may *not* be the same - as the `ArrayBuffer` belonging to the input view. - - For purposes of generality, always treat the output collection as distinct - from the input collection. - - Parameters - ---------- - collection1: Array|TypedArray|Object - A collection. If the collection is an `Object`, the collection should be - array-like. - - collection2: Array|TypedArray|Object - A collection containing the elements to add. If the collection is an - `Object`, the collection should be array-like. - - Returns - ------- - out: Array|TypedArray|Object - Updated collection. - - Examples - -------- - // Arrays: - > var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - > arr = {{alias}}( arr, [ 6.0, 7.0 ] ) - [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] - - // Typed arrays: - > arr = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); - > arr = {{alias}}( arr, [ 3.0, 4.0 ] ) - [ 3.0, 4.0, 1.0, 2.0 ] - - // Array-like object: - > arr = { 'length': 1, '0': 1.0 }; - > arr = {{alias}}( arr, [ 2.0, 3.0 ] ) - { 'length': 3, '0': 2.0, '1': 3.0, '2': 1.0 } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0cc99ff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 prepend = require( './index' ); - - -// TESTS // - -// The function returns a collection... -{ - prepend( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection - prepend( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection - prepend( [ true, true ], [ false, false ] ); // $ExpectType Collection -} - -// The compiler throws an error if the function is provided a first argument which is not a collection... -{ - prepend( true, [] ); // $ExpectError - prepend( false, [] ); // $ExpectError - prepend( 5, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a collection... -{ - prepend( [], true ); // $ExpectError - prepend( [], false ); // $ExpectError - prepend( [], 5 ); // $ExpectError -} - -// The compiler throws an error if the function is not provided two arguments... -{ - prepend(); // $ExpectError - prepend( [ true, true ] ); // $ExpectError - prepend( [ true, true ], [ true, false ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 835c157..0000000 --- a/examples/index.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var prepend = require( './../lib' ); - -var arr; -var i; -var j; - -arr = new Float64Array(); -for ( i = 0; i < 100; i++ ) { - j = i * 3; - arr = prepend( arr, [ j+2, j+1, j ] ); -} -console.log( arr ); -console.log( 'View Length: %d', arr.byteLength ); -console.log( 'Buffer Length: %d', arr.buffer.byteLength ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 95% rename from docs/types/index.d.ts rename to index.d.ts index 8c326e8..18fa31c 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8efe6f4 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";function l(l,f){if(!e(f))throw new TypeError(n("1Wn2y",f));if(t(l))return function(t,e){var r;for(r=e.length-1;r>=0;r--)t.unshift(e[r]);return t}(l,f);if(r(l))return function(t,e){var r,s,n,l,f,m,d,h;if(l=t.length,s=(m=e.length)*t.BYTES_PER_ELEMENT,(n=t.byteOffset)=0)return function(t,e){var r,s,n;for(r=t.length,s=e.length,n=r-1;n>=0;n--)t[n+s]=t[n];for(n=0;n[ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( collection1, collection2 ) {\n\tif ( !isCollection( collection2 ) ) {\n\t\tthrow new TypeError( format( '1Wn2y', collection2 ) );\n\t}\n\tif ( isArray( collection1 ) ) {\n\t\treturn prependArray( collection1, collection2 );\n\t}\n\t// Check for a typed-array-like object, as verifying actual typed arrays is expensive...\n\tif ( isTypedArrayLike( collection1 ) ) {\n\t\treturn prependTypedArray( collection1, collection2 );\n\t}\n\t// Check for an array-like object...\n\tif (\n\t\tcollection1 !== null &&\n\t\ttypeof collection1 === 'object' &&\n\t\ttypeof collection1.length === 'number' &&\n\t\tisInteger( collection1.length ) &&\n\t\tcollection1.length >= 0\n\t) {\n\t\treturn prependObject( collection1, collection2 );\n\t}\n\tthrow new TypeError( format( '1WnAi', collection1 ) );\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array.\n*\n* @private\n* @param {Array} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {Array} input array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar i;\n\tfor ( i = items.length-1; i >= 0; i-- ) {\n\t\tarr.unshift( items[ i ] );\n\t}\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport ceil2 from '@stdlib/math-base-special-ceil2'; // TODO: nextpow2\n\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of a typed array.\n*\n* ## Notes\n*\n* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements).\n* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities).\n*\n* @private\n* @param {TypedArray} arr - input array\n* @param {ArrayLike} items - items to add\n* @returns {TypedArray} input array\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );\n* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*\n* arr = prepend( arr, [ 6.0, 7.0 ] );\n* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction prepend( arr, items ) {\n\tvar nbytes;\n\tvar ibytes;\n\tvar offset;\n\tvar total;\n\tvar len;\n\tvar buf;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tlen = arr.length;\n\tn = items.length;\n\n\tibytes = n * arr.BYTES_PER_ELEMENT;\n\toffset = arr.byteOffset;\n\n\tif ( offset < ibytes ) {\n\t\tnbytes = len * arr.BYTES_PER_ELEMENT;\n\t\ttotal = nbytes + ibytes + offset;\n\t\tbuf = new ArrayBuffer( ceil2( total+1 ) );\n\t\toffset = buf.byteLength - nbytes - ibytes;\n\t\tv = new arr.constructor( buf, offset, len+n );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv[ i+n ] = arr[ i ];\n\t\t}\n\t} else {\n\t\toffset -= ibytes;\n\t\tv = new arr.constructor( arr.buffer, offset, len+n );\n\t}\n\tfor ( i = 0; i < n; i++ ) {\n\t\tv[ i ] = items[ i ];\n\t}\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Adds elements from a collection to the beginning of an array-like object.\n*\n* @private\n* @param {Object} obj - input array-like object\n* @param {ArrayLike} items - items to add\n* @returns {Object} input object\n*\n* @example\n* var obj = {\n* 'length': 2,\n* '0': 1.0,\n* '1': 2.0\n* };\n*\n* obj = prepend( obj, [ 3.0, 4.0 ] );\n* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 }\n*/\nfunction prepend( obj, items ) {\n\tvar len;\n\tvar n;\n\tvar i;\n\n\tlen = obj.length;\n\tn = items.length;\n\n\t// Shift all existing elements to the right...\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tobj[ i+n ] = obj[ i ];\n\t}\n\t// Add new elements...\n\tfor ( i = 0; i < n; i++ ) {\n\t\tobj[ i ] = items[ i ];\n\t}\n\tobj.length = len + n;\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nexport default prepend;\n"],"names":["prepend","collection1","collection2","isCollection","TypeError","format","isArray","arr","items","i","length","unshift","prependArray","isTypedArrayLike","nbytes","ibytes","offset","len","buf","n","v","BYTES_PER_ELEMENT","byteOffset","ArrayBuffer","ceil2","byteLength","constructor","buffer","prependTypedArray","isInteger","obj","prependObject"],"mappings":";;opBA0DA,SAASA,EAASC,EAAaC,GAC9B,IAAMC,EAAcD,GACnB,MAAM,IAAIE,UAAWC,EAAQ,QAASH,IAEvC,GAAKI,EAASL,GACb,OC3BF,SAAkBM,EAAKC,GACtB,IAAIC,EACJ,IAAMA,EAAID,EAAME,OAAO,EAAGD,GAAK,EAAGA,IACjCF,EAAII,QAASH,EAAOC,IAErB,OAAOF,CACR,CDqBSK,CAAcX,EAAaC,GAGnC,GAAKW,EAAkBZ,GACtB,OEjBF,SAAkBM,EAAKC,GACtB,IAAIM,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAX,EAQJ,GANAQ,EAAMV,EAAIG,OAGVK,GAFAI,EAAIX,EAAME,QAEGH,EAAIc,mBACjBL,EAAST,EAAIe,YAECP,EAMb,IALAD,EAASG,EAAMV,EAAIc,kBAGnBL,GADAE,EAAM,IAAIK,EAAaC,EADfV,EAASC,EAASC,EACU,KACvBS,WAAaX,EAASC,EACnCK,EAAI,IAAIb,EAAImB,YAAaR,EAAKF,EAAQC,EAAIE,GACpCV,EAAI,EAAGA,EAAIQ,EAAKR,IACrBW,EAAGX,EAAEU,GAAMZ,EAAKE,QAGjBO,GAAUD,EACVK,EAAI,IAAIb,EAAImB,YAAanB,EAAIoB,OAAQX,EAAQC,EAAIE,GAElD,IAAMV,EAAI,EAAGA,EAAIU,EAAGV,IACnBW,EAAGX,GAAMD,EAAOC,GAEjB,OAAOW,CACR,CFjBSQ,CAAmB3B,EAAaC,GAGxC,GACiB,OAAhBD,GACuB,iBAAhBA,GACuB,iBAAvBA,EAAYS,QACnBmB,EAAW5B,EAAYS,SACvBT,EAAYS,QAAU,EAEtB,OGrCF,SAAkBoB,EAAKtB,GACtB,IAAIS,EACAE,EACAV,EAMJ,IAJAQ,EAAMa,EAAIpB,OACVS,EAAIX,EAAME,OAGJD,EAAIQ,EAAI,EAAGR,GAAK,EAAGA,IACxBqB,EAAKrB,EAAEU,GAAMW,EAAKrB,GAGnB,IAAMA,EAAI,EAAGA,EAAIU,EAAGV,IACnBqB,EAAKrB,GAAMD,EAAOC,GAGnB,OADAqB,EAAIpB,OAASO,EAAME,EACZW,CACR,CHmBSC,CAAe9B,EAAaC,GAEpC,MAAM,IAAIE,UAAWC,EAAQ,QAASJ,GACvC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 05faf85..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Add the elements of one collection to the beginning of another collection. -* -* @module @stdlib/utils-prepend -* -* @example -* var prepend = require( '@stdlib/utils-prepend' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// 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 b5ce493..0000000 --- a/lib/main.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArray = require( '@stdlib/assert-is-array' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isInteger = require( '@stdlib/assert-is-integer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var prependArray = require( './prepend_array.js' ); -var prependObject = require( './prepend_object.js' ); -var prependTypedArray = require( './prepend_typed_array.js' ); - - -// MAIN // - -/** -* Adds elements from one collection to the beginning of another collection. -* -* @param {Collection} collection1 - collection -* @param {Collection} collection2 - collection containing elements to add -* @throws {TypeError} first argument must be either an array, typed array, or an array-like object -* @throws {TypeError} second argument must be an array-like object -* @returns {Collection} updated collection -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( collection1, collection2 ) { - if ( !isCollection( collection2 ) ) { - throw new TypeError( format( '1Wn2y', collection2 ) ); - } - if ( isArray( collection1 ) ) { - return prependArray( collection1, collection2 ); - } - // Check for a typed-array-like object, as verifying actual typed arrays is expensive... - if ( isTypedArrayLike( collection1 ) ) { - return prependTypedArray( collection1, collection2 ); - } - // Check for an array-like object... - if ( - collection1 !== null && - typeof collection1 === 'object' && - typeof collection1.length === 'number' && - isInteger( collection1.length ) && - collection1.length >= 0 - ) { - return prependObject( collection1, collection2 ); - } - throw new TypeError( format( '1WnAi', collection1 ) ); -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_array.js b/lib/prepend_array.js deleted file mode 100644 index b65fc6f..0000000 --- a/lib/prepend_array.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array. -* -* @private -* @param {Array} arr - input array -* @param {ArrayLike} items - items to add -* @returns {Array} input array -* -* @example -* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var i; - for ( i = items.length-1; i >= 0; i-- ) { - arr.unshift( items[ i ] ); - } - return arr; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_object.js b/lib/prepend_object.js deleted file mode 100644 index 950c490..0000000 --- a/lib/prepend_object.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Adds elements from a collection to the beginning of an array-like object. -* -* @private -* @param {Object} obj - input array-like object -* @param {ArrayLike} items - items to add -* @returns {Object} input object -* -* @example -* var obj = { -* 'length': 2, -* '0': 1.0, -* '1': 2.0 -* }; -* -* obj = prepend( obj, [ 3.0, 4.0 ] ); -* // returns { 'length': 4, '0': 3.0, '1': 4.0, '2': 1.0, '3': 2.0 } -*/ -function prepend( obj, items ) { - var len; - var n; - var i; - - len = obj.length; - n = items.length; - - // Shift all existing elements to the right... - for ( i = len-1; i >= 0; i-- ) { - obj[ i+n ] = obj[ i ]; - } - // Add new elements... - for ( i = 0; i < n; i++ ) { - obj[ i ] = items[ i ]; - } - obj.length = len + n; - return obj; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/lib/prepend_typed_array.js b/lib/prepend_typed_array.js deleted file mode 100644 index 3e88278..0000000 --- a/lib/prepend_typed_array.js +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); // TODO: nextpow2 - - -// MAIN // - -/** -* Adds elements from a collection to the beginning of a typed array. -* -* ## Notes -* -* - If the underlying `ArrayBuffer` is too short, we need to copy the data to a new `ArrayBuffer`. To do so, we allocate a new `ArrayBuffer` in a manner similar to how `Arrays` are resized (i.e., allocate enough memory to hold `nextpow2(n)` elements). -* - Beware that, if an ArrayBuffer view is preceded by one or more other views, the created view may contain elements from those views, thus resulting in possible mutation. Accordingly, providing a typed array view having a shared underlying `ArrayBuffer` may have unintended consequences (including security vulnerabilities). -* -* @private -* @param {TypedArray} arr - input array -* @param {ArrayLike} items - items to add -* @returns {TypedArray} input array -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* -* arr = prepend( arr, [ 6.0, 7.0 ] ); -* // returns [ 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function prepend( arr, items ) { - var nbytes; - var ibytes; - var offset; - var total; - var len; - var buf; - var n; - var v; - var i; - - len = arr.length; - n = items.length; - - ibytes = n * arr.BYTES_PER_ELEMENT; - offset = arr.byteOffset; - - if ( offset < ibytes ) { - nbytes = len * arr.BYTES_PER_ELEMENT; - total = nbytes + ibytes + offset; - buf = new ArrayBuffer( ceil2( total+1 ) ); - offset = buf.byteLength - nbytes - ibytes; - v = new arr.constructor( buf, offset, len+n ); - for ( i = 0; i < len; i++ ) { - v[ i+n ] = arr[ i ]; - } - } else { - offset -= ibytes; - v = new arr.constructor( arr.buffer, offset, len+n ); - } - for ( i = 0; i < n; i++ ) { - v[ i ] = items[ i ]; - } - return v; -} - - -// EXPORTS // - -module.exports = prepend; diff --git a/package.json b/package.json index a8829c7..a2b4b41 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Add elements from one collection to the beginning of another collection.", "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,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/constants-int16-max": "^0.2.2", - "@stdlib/constants-int32-max": "^0.3.0", - "@stdlib/constants-int8-max": "^0.2.2", - "@stdlib/constants-uint16-max": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/constants-uint8-max": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e41ad6e --- /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 f4c16b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable object-curly-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var prepend = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof prepend, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either an array, typed array, or an array-like object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( value, [ 1.0 ] ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object', function test( t ) { - var values; - var i; - - values = [ - // '5', // this is considered array-like - 5, - NaN, - true, - false, - null, - void 0, - function noop() {}, - new Date(), - new RegExp( '.+' ), // eslint-disable-line prefer-regex-literals - {}, - { 'length': null }, - { 'length': -1 }, - { 'length': 3.14 } - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - prepend( [ 1.0, 2.0 ], value ); - }; - } -}); - -tape( 'the function adds the elements of a collection to an array', function test( t ) { - var expected; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; - out = prepend( arr, [ 6.0 ] ); - - t.strictEqual( out, arr, 'returns input array' ); - - expected = [ 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 7.0, 8.0 ] ); - - expected = [ 7.0, 8.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds the elements of a collection to an array-like object', function test( t ) { - var expected; - var arr; - var out; - - arr = { - 'length': 0 - }; - out = prepend( arr, [ 1.0 ] ); - - t.strictEqual( out, arr, 'returns input collection' ); - - expected = { - 'length': 1, - '0': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - out = prepend( arr, [ 2.0, 3.0 ] ); - - expected = { - 'length': 3, - '0': 2.0, - '1': 3.0, - '2': 1.0 - }; - t.deepEqual( arr, expected, 'deep equal' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array', function test( t ) { - var expected; - var arr; - var out; - var i; - - arr = new Float64Array(); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (preallocated buffer)', function test( t ) { - var expected; - var buf; - var arr; - var out; - var i; - - buf = new ArrayBuffer( 64000 ); - arr = new Float64Array( buf, buf.byteLength, 0 ); - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds one or more elements to a typed array (offset view)', function test( t ) { - var expected; - var arr; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 32 ); - arr = new Float64Array( buf, 3*8, 0 ); // 8 bytes per double - out = prepend( arr, [ 1.0 ] ); - - t.notEqual( out, arr, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr.buffer, 'same underlying buffer' ); - - out = prepend( out, [ 2.0, 3.0, 4.0 ] ); - - expected = new Float64Array( [ 2.0, 3.0, 4.0, 1.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - // eslint-disable-next-line max-len - out = prepend( out, [ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ] ); - - expected = new Float64Array([ - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 2.0, - 3.0, - 4.0, - 1.0 - ]); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.notEqual( out.buffer, arr.buffer, 'new underlying buffer' ); - - t.end(); -}); - -tape( 'the function adds elements from a collection to a typed array (shared `ArrayBuffer`)', function test( t ) { - var expected; - var arr1; - var arr2; - var arr3; - var buf; - var out; - var i; - - buf = new ArrayBuffer( 64 ); - - arr1 = new Float64Array( buf, 2*8, 2 ); // 8 bytes per double - arr2 = new Float64Array( buf, 4*8, 2 ); - arr3 = new Float64Array( buf, 6*8, 0 ); - - arr1[ 0 ] = 3.14; - arr1[ 1 ] = 6.28; - - arr2[ 0 ] = -3.14; - arr2[ 1 ] = -6.28; - - out = prepend( arr3, [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - t.notEqual( out, arr3, 'does not return input array (new view)' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( out[ i ], expected[ i ], 'has expected value for element '+i ); - } - t.strictEqual( out.buffer, arr3.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 5.0, 6.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr2[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr2.buffer, 'same underlying buffer' ); - - expected = new Float64Array( [ 3.0, 4.0 ] ); - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( arr1[ i ], expected[ i ], 'value was overwritten for element '+i ); - } - t.strictEqual( out.buffer, arr1.buffer, 'same underlying buffer' ); - - t.end(); -});